package com.credit.jumu.playcard.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.credit.jumu.playcard.R;
import com.credit.jumu.playcard.activity.BindingCardActivity;
import com.credit.jumu.playcard.activity.CreditCardAllActivity;
import com.credit.jumu.playcard.activity.RepaymentActivity;
import com.credit.jumu.playcard.activity.RepaymentSetActivity;
import com.credit.jumu.playcard.adapter.CardListAdapter;
import com.credit.jumu.playcard.bean.CardInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by jpeng on 16-11-14.
 */
public class PlanTabFragment extends Fragment {
	LinearLayout addcreditcard;
	RelativeLayout torepayment;
	ListView myplanlist;
	List cardData = new ArrayList<CardInfo>();
	CardListAdapter cardListAdapter;
	View endView;

	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_plantab, null);
		endView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_planend, null);
		myplanlist = view.findViewById(R.id.myplanlist);
		cardListAdapter = new CardListAdapter(cardData, getActivity());
		myplanlist.setAdapter(cardListAdapter);
		myplanlist.addFooterView(endView);
		myplanlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Intent intent = new Intent(getActivity(), RepaymentActivity.class);
				startActivity(intent);
			}
		});
		initView();
		setData();
		return view;
	}

	private void setData() {
		CardInfo mCardInfo = new CardInfo();
		mCardInfo.setCardIcon("http://test.juhexinyong.com/static/upload/product/1d48be7ace6f3dac9b256af2176900e7.png");
		mCardInfo.setCardNume("招商银行 信用卡");
		mCardInfo.setCardNum("848484876******8568");
		cardData.add(mCardInfo);
		cardData.add(mCardInfo);
		cardData.add(mCardInfo);
		if (null != cardListAdapter) {
			cardListAdapter.notifyDataSetChanged();
		}
	}

	private void initView() {
//		torepayment.setOnClickListener(new_icon View.OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				Intent intent = new_icon Intent(getActivity(), RepaymentActivity.class);
//				intent.putExtra("type", "binding");
//				startActivity(intent);
//			}
//		});
		endView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), BindingCardActivity.class);
				intent.putExtra("type", "addcredit");
				startActivity(intent);
			}
		});
	}

}